package com.demo.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

//2.标识出当前 Servlet 的 URL 地址
//标识 Servlet 路径时 最前面一定要加 /
//这个 / 代表 http://localhost:8080/demo0221/
@WebServlet("/client/register.do")
public class Demo01Servlet extends HttpServlet {
    //1.让自己创建的类 继承于 HttpServlet

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //对浏览器传来的参数信息进行获取
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String sex = request.getParameter("sex");
        String email = request.getParameter("email");
        String phone = request.getParameter("phone");
        String[] tech = request.getParameterValues("tech");
        String country = request.getParameter("country");
        String introduction = request.getParameter("introduction");
        //
        System.out.println();
        //服务器回传给浏览器数据
        //设定字符编码
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.write("<h1>注册成功！</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("前端以 POST 方式请求");
        doGet(req, resp);
    }
}
